<?php

namespace Government\Model;

use \Mongo;
use \MongoId;
use \ArrayObject;

class GovernmentService{
	
	/**
	 * @var \Mongo
	 */
	private $_mongo;

	/**
	 * Constructor.
	 * This constructor creates a MongoDB connection object.
	 * this has to be changed so that the Mongo object in 
	 * injected via Dependenci Injection Contructor Pattern.
	 * @todo make DI
	 *
	 */
	public function __construct(){
		$this->_mongo = new Mongo();
	}

	/**
	 * @todo if resource not found;
	 */
	public function find( $id ){
		$database = $this->_mongo->government;
    	$collection = $database->governments;

    	return $collection->findOne( array("_id"=> new MongoId($id) ) );
	}

	/**
	 * List all Governments with as little informations as possible
	 *
	 * @return ArrayObject
	 */
	public function listAll(){
		$return = array();
    	$database = $this->_mongo->government;
    	$collection = $database->governments;
    	foreach($collection->find(array(),array("name"=>true,"description"=>true,"from"=>true,"to"=>true)) as $item){
	   		$return[] = $item ;
    	}
    	return $return;
	}

}